home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / exec.swg / 0012_Search Execute.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-10-28  |  1.6 KB  |  56 lines

  1. {===========================================================================
  2. Date: 09-18-93 (23:25)
  3. From: MIKE DICKSON
  4. Subj: EXEC ()
  5. ---------------------------------------------------------------------------
  6. [MM]  ▒ I've written my own EXEC function that performs an FSearch() on the
  7. [MM] Well, that's great. (Why don't you post it!).
  8.  
  9. Okay...here's an illustrative little program... }
  10.  
  11. {$M $4000,0,0 }
  12. Program JohnMajorHadBetterResignPrettyDamnedShortly;
  13.  
  14. Uses DOS;
  15.  
  16. FUNCTION  FileExists (FileName: String):Boolean;{ Checks if file
  17. exists  } var
  18.    Attr : Word;
  19.    f    : file;
  20. begin
  21.    Assign (f, Filename);
  22.    GetFAttr(f, attr);
  23.    FileExists := (DOSError = 0);
  24. end;
  25.  
  26. FUNCTION SearchExec (ProgramName, Parameters : String) : Integer;
  27. var
  28.    Result : Integer;
  29. begin
  30. { If the program doesn't exist then search on the %PATH for it }
  31.    If Not FileExists(ProgramName) then
  32.       ProgramName := FSearch(ProgramName, GetEnv('PATH'));
  33.  
  34. { If it's a batch file then call it through the command processor }
  35.    If Pos('.BAT', ProgramName) <> 0 then begin
  36.       Parameters := '/C '+ProgramName+' '+Parameters;
  37.       ProgramName := GetEnv('COMSPEC');
  38.    end;
  39.  
  40. { Now call the program...if it didn't exist the set DOSError to 2 }
  41.    If ProgramName <> '' then begin
  42.       SwapVectors;
  43.       Exec (ProgramName, Parameters);
  44.       Result := DOSError;
  45.       SwapVectors;
  46.       SearchExec := Result;
  47.    end else SearchExec := 2;
  48.  
  49. end;
  50.  
  51. begin
  52.    If SearchExec ('AUTOEXEC.BAT', '/?') <> 0
  53.       then writeln ('Execution was okay!')
  54.       else writeln ('Execution was NOT okay!');
  55. end.
  56.